package model.Exception;

import io.jsonwebtoken.ExpiredJwtException;
import model.User.entity.Result;
import model.User.entity.StatusCode;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by Sunshine、宸 on 2019/7/2.
 */
@ControllerAdvice
public class MyExceptionHandel {
    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public Result defaultExceptionHandler(HttpServletRequest request, HttpServletResponse response,Exception exception) throws IOException{
        if(exception instanceof ExpiredJwtException){
            return new Result(false, StatusCode.ACCESSERROR,"token失效，请您重新登陆！");
        }else {
            return new Result(false,StatusCode.ERROR,"请您先登陆！");
        }
    }
}
